package com.cheer.dto;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import com.cheer.enums.RegisterStatusEnum;
import com.cheer.enums.ReviewTypeEnum;
import com.cheer.enums.TitleEnum;
import com.google.common.collect.Maps;
import lombok.Data;
import lombok.experimental.Accessors;

import java.text.NumberFormat;
import java.util.Date;
import java.util.Map;

@Data
@Accessors(chain = true)
public class ApplicantExportDTO {

    private static Map<String, String> headerAlias = Maps.newLinkedHashMap();

    static {
        headerAlias.put("number", "序号");
        headerAlias.put("applicantName", "集体名称");
        headerAlias.put("orgName", "所属组织");
        headerAlias.put("contactPerson", "45周岁以下负责人姓名");
        headerAlias.put("contactPersonPost", "45周岁以下负责人职务");
        headerAlias.put("contactPersonBirthMonth", "45周岁以下负责人出生年月");
        headerAlias.put("phoneAccount", "号长手机号");
        headerAlias.put("personNumber", "职工人数");
        headerAlias.put("youthNumber", "35周岁以下青年人数");
        headerAlias.put("youthPercent", "35周岁以下青年人数比例");
        headerAlias.put("applicantStatus", "文明号状态");
        headerAlias.put("registerTime", "申请日期");
        headerAlias.put("status", "审核状态");
        headerAlias.put("joinReview", "联合审核");
        headerAlias.put("phone", "集体手机号");
        headerAlias.put("email", "集体邮箱");
        headerAlias.put("address", "集体地址");
        headerAlias.put("remark", "备注");
    }

    private String number;

    private String applicantName;

    private String orgName;

    private Integer registerStatus;

    private String status;

    private String phoneAccount;

    private String contactPerson;

    private String contactPersonPost;

    private Date contactPersonBirth;

    private String contactPersonBirthMonth;

    private Integer personNumber;

    private Integer youthNumber;

    private String youthPercent;

    private String applicantStatus;

    private Integer registerTitle;

    private String phone;

    private String email;

    private String address;

    private String remark;

    private Date createTime;

    private String registerTime;

    private Integer reviewType;

    private String joinReview;

    public static Map<String, String> getHeaderAlias() {
        return headerAlias;
    }

    public void fill(Integer index) {
        number = String.valueOf(index);
        contactPersonBirthMonth = DateUtil.format(contactPersonBirth, DatePattern.NORM_DATE_FORMAT);
        NumberFormat nt = NumberFormat.getPercentInstance();
        youthPercent = nt.format(1.0 * youthNumber / personNumber);
        TitleEnum title = TitleEnum.getByType(registerTitle);
        if (title != null) {
            if (title == TitleEnum.NO) {
                applicantStatus = "新申请";
            } else {
                applicantStatus = "已获得" + title.getDescription();
            }
        }
        registerTime = DateUtil.formatDate(createTime);
        if (registerStatus < RegisterStatusEnum.CITY_TITLE.getCode()) {
            status = "待审核";
        } else {
            status = "已通过";
        }
        if (reviewType == ReviewTypeEnum.COMMON.getCode()) {
            joinReview = "否";
        } else {
            joinReview = "是";
        }
    }

}
